<?php
/**
 * Created by PhpStorm.
 * Author: Shadow
 * Date: 2022/5/31
 * Time: 4:53 下午
 * description: list.php
 * 通过PDO的形式实现分页展示数据、静态化 git工具
 */

try {
    $pdo = new PDO("mysql:host=127.0.0.1;dbname=2004a",'root','password');

    # 查询数据

    $sql = "SELECT * FROM article";

    $result = $pdo->query($sql);

    $data = $result->fetchAll(PDO::FETCH_ASSOC);//获取结果集中的所有 PDO::FETCH_ASSOC 以关联数组的形式、返回

//    print_r($data);

}catch (PDOException $exception) {
    echo  "错误信息";
    print_r($exception->getMessage());
}
?>
<center>
<!--    <meta name="referer" content="no-referer">-->
    <table border="1">
        <tr>
            <th>ID</th>
            <th>标题</th>
            <th>图片</th>
            <th>操作</th>
        </tr>
        <?php foreach ($data as $value) {?>
            <tr>
                <td><?php echo $value['id'];?></td>
                <td><?php echo $value['title'];?></td>
                <td><img src="<?php echo $value['image']?>" width="80px" height="80px" alt=""></td>
                <td>
                    <a href="./delete.php?id=<?php echo $value['id'];?>">删除</a>
                    <a href="./detail.php?id=<?php echo $value['id'];?>">查询详情</a>
                </td>
            </tr>
        <?php }?>
    </table>
</center>
